<!--  -->
<template>
  <div class="layout">
    <div class="investment-box" v-loading="_loading">
      <div style="display: flex; justify-content: space-between; margin-top: 20px;">
        <Breadcrumb class="breadcrumb" :crumbs="crumbs" style="margin-bottom: 20px;"></Breadcrumb>
      </div>
      <div class="dynamicsDetails">
        <div class="contentCss" :style="!relatedInformationList.length ? 'width:100%' : ''">
          <div class="contentCssName">{{ this.Details.title}}</div>
          <div class="releaseTime">
            <div class="movement width1">发布时间:{{publishTime}}</div>
            <div class="movement width2">来源:{{this.Details.source}}</div>
            <div class="movement width3">{{this.Details.pv}}次浏览</div>
          </div>
          <div class="introduce">
            <div class="introduce_Content">{{this.Details.subtitle}}</div>
          </div>
          <div class="contentInformation" v-if="this.Details && this.Details.content" 
          v-html="this.Details.content.replace(/<img/g,'<img style=max-width:100%;height:auto;').replace(/<p><img/g,'<img').replace(/\/img><\/p>/g,'/img>')">
          </div>
        </div>
        <div class="associatedBuildings" v-if="relatedInformationList.length">
          <div class="associated_Buildings">
            <div class="associated_BuildingsName">关联楼宇</div>
            <el-divider></el-divider>
            <div class="relatedInformation">
              <div
                class="careful"
                v-for="(item,index) in relatedInformationList"
                @click="onJump(item)"
                :key="index"
                v-show="item.canRegister!=0"
              >
                <div class="pictureCss">
                  <PublicImage
                    v-if="item.buildingImages == ''"
                    :src="require('@/assets/image/finance/product_dj.png')"
                  ></PublicImage>
                  <PublicImage
                    v-else-if="item.buildingImages.length!=0"
                    :src="item.buildingImages[0] || item.buildingImages[1]"
                  ></PublicImage>
                  <PublicImage
                    v-else
                    :src="item.buildingImages"
                  ></PublicImage>
                </div>
                <div class="building_Information">
                  <div class="DaxiaName ellipsis">{{item.buildingName}}</div>
                  <div class="option ellipsis">{{item.address}}</div>
                  <div class="option">{{Grade}}</div>
                  <!-- <div
                    class="option"
                  >地上{{item.aboveGroundFloors}}层地下{{item.undergroundFloors}}层楼高{{item.buildingHeight}}米高{{item.buildingHeight}}米</div> -->
                  <div v-if="item.floorType != 1 && item.floorType" class="option">
                    地上{{item.aboveGroundFloors}}层<span style="margin:0 10px;">地下{{item.undergroundFloors}}层</span>楼高{{item.buildingHeight}}米
                  </div>
                  <div v-if="item.floorType == 1 && item.floorType" class="option">
                    单层{{item.buildingFloor}}层
                  </div>
                </div>
                <div class="many">
                  <div class="multiple_Choice" v-show="item.industryType">
                    <div class="Choice_Name">{{item.industryType}}</div>
                  </div>
                  <div class="multiple_Choice" v-show="item.buildingType">
                    <div class="Choice_Name">{{item.buildingType}}</div>
                  </div>
                  <div class="multiple_Choice" v-show="item.buildingDecorationType">
                    <div class="Choice_Name">{{item.buildingDecorationType}}</div>
                  </div>
                  <div class="multiple_Choice" v-show="item.canRegister =='可注册'">
                    <div class="Choice_Name">{{item.canRegister}}</div>
                  </div>
                  <div class="multiple_Choice" v-show="item.relatedPoliciesNum != 0">
                    <div class="Choice_Name">政策扶持</div>
                  </div>
                </div>
              </div>
            </div>
            <div
              class="view_More"
              v-if="moreBuildings"
              @click="buildings"
            >查看更多关联楼宇</div>
          </div>
        </div>
      </div>
      <div class="moreDynamic">
        <div class="head">
          <ContainerTitle text="更多动态" @jump="onMoreDynamic" :more="true"></ContainerTitle>
          <div class="More_Dynamic">
            <div class="whole">
              <div
                class="allCarefully"
                @click="onMoredynamic(item)"
                v-for="(item,index) in More_DynamicList "
                :key="index"
              >
                <div class="picturewhole">
                  <PublicImage
                    v-if="item.logo ==''"
                    :src="require('@/assets/image/finance/product_dj.png')"
                  ></PublicImage>
                  <PublicImage v-else :src="item.logo"></PublicImage>
                </div>
                <div class="letter">
                  <div class="writtenWords">
                    <div class="head_Name">{{item.title}}</div>
                    <div class="content_Name">{{item.subtitle}}</div>
                  </div>
                  <div class="SourceLetter">
                    <div class="sourceCss">来源:{{item.source}}</div>
                    <div class="dateCss">{{item.publishTime}}</div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="ViewDetails">
        <Buttons :buttons="buttons" @goBack="back"></Buttons>
      </div>
    </div>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import Breadcrumb from '@/components/breadcrumb'
import { getDynamicsDetails, getAssociatedBuilding, getDynamicsRecomendList } from '@/common/api/investment'

export default {
  //import引入的组件需要注入到对象中才能使用
  components: {
    Breadcrumb,
  },
  data() {
    //这里存放数据
    return {
      buttons: [{ text: "返回", type: "normal", size: "l", method: "goBack" }],
      _loading:false,
      crumbs: [
        {
          label: '招商中心',
          value: 'investment',
        },
        { label: '楼宇动态列表', value: 'investmenDynamictList' },
        { label: '楼宇动态详情', value: '', choose: true },
      ],
      moreBuildings:false, // 更多楼宇是否展示
      relatedInformationList: [],
      More_DynamicList: [],
      Details: '', //楼宇动态详情
      publishTime: '', //发布时间
      Grade: '', //等级
      positionList: [], //位置
      typeList: [], //类型
      gradeList: [], //等级
      canRegisterList: [], //是否可注册
      buildingDecorationTypeList: [], //装修情况
      manylist: [], //楼宇类型
      publishTimeA: '', //发布时间
      industryTypeList: [], //
    }
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    onMoredynamic(item) {
      this.$router.push({
        path: '/investment/investmenDynamictDetails',
        query: { id: item.id },
      })
      this.dictionaryQuery()
      this.buildingDynamicsDetails()
      this.associatedBuilding()
      this.dynamicRelatedRecommendation()
    },
    buildings() {
      var id = this.$route.query.id
      this.$router.push({
        path: '/investment/Associatedbuildinglist',
        query: { id: id },
      })
    },
    //返回更多动态
    onMoreDynamic() {
      this.$router.replace('/investment/investmenDynamictList')
    },
    back() {
      this.$router.replace('/investment/investmenDynamictList')
    },
    onJump(item) {
      this.$router.push({
        path: '/investment/investmentdetails',
        query: { id: item.id },
      })
    },
    async buildingDynamicsDetails() {
      var id = this.$route.query.id
      let obj = {
        buildingInfoId: id
      }
      let {code, data, msg} = await getDynamicsDetails(obj)
      if (code != "200") return this.$message.warning(msg);
      this.Details = data
      var date = new Date(this.Details.publishTime)
      var N = date.getFullYear()
      var Y = date.getMonth() + 1
      Y = Y < 10 ? '0' + Y : Y
      var R = date.getDate()
      R = R < 10 ? '0' + R : R
      this.publishTime = N + '年' + Y + '月' + R + '日'
    },
    // 获取关联楼宇列表
    async associatedBuilding() {
      var pageSize = 3
      var pageNum = 1
      var id = this.$route.query.id
      var data = {
        buildingDynamicsId: id,
        pageNum: pageNum,
        pageSize: pageSize,
      }
      let { code, msg, rows, total } = await getAssociatedBuilding(data)
      if (code != "200") return this.$message.warning(msg);
      this.relatedInformationList = rows
      if(total > 3){
        this.moreBuildings = true
      }
      var classificationList = []
      this.relatedInformationList.forEach((item, index) => {
        item.buildingImages = item.buildingImages.split(',')
        //等级
        this.gradeList.forEach((itemy, indexy) => {
          if (item.buildingLeave == Number(itemy.dictValue)) {
            this.Grade = itemy.dictLabel
          }
        })
        //类型
        this.typeList.forEach((itemq, indexq) => {
          if (item.buildingType == Number(itemq.dictValue)) {
            item.buildingType = itemq.dictLabel
          }
        })
        //装修情况
        this.buildingDecorationTypeList.forEach((itema, indexa) => {
          if (item.buildingDecorationType == Number(itema.dictValue)) {
            classificationList.push(itema.dictLabel)
            item.buildingDecorationType = itema.dictLabel
          }
        })
        //是否可注册
        this.canRegisterList.forEach((items, indexs) => {
          if (item.canRegister == Number(items.dictValue)) {
            item.canRegister = items.dictLabel
          }
        })
        //楼宇产业领域
        this.industryTypeList.forEach((itemr, indexx) => {
          if (item.industryType == Number(itemr.dictValue)) {
            item.industryType = itemr.dictLabel
          }
        })
      })
      this.manylist = classificationList
      this._loading = false;
    },
    //字典方法接口
    async dictionaryQuery() {
      let api = `building_type,building_leave,street_code,building_register_state,building_decoration_type,building_industry`
      // 调用公共方法中的查询字典表
      this.getDictList(this,api).then(res => {
        this.positionList = res.street_code //位置
        this.typeList = res.building_type //类型
        this.gradeList = res.building_leave //等级
        this.industryTypeList = res.building_industry //楼宇产业领域
        this.canRegisterList = res.building_register_state //是否可注册
        this.buildingDecorationTypeList = res.building_decoration_type //装修情况
      })
    },
    //获取更多动态列表
    async dynamicRelatedRecommendation() {
      var pageSize = 4
      var pageNum = 1
      var data = {
        id: this.$route.query.id,
        pageSize: pageSize,
        pageNum: pageNum,
      }
      let { code, msg, rows, total } = await getDynamicsRecomendList(data)
      if (code != "200") return this.$message.warning(msg);
      this.More_DynamicList = rows

      this.More_DynamicList.forEach((item, index) => {
        var date = new Date(item.publishTime)
        var N = date.getFullYear()
        var Y = date.getMonth() + 1
        Y = Y < 10 ? '0' + Y : Y
        var R = date.getDate()
        R = R < 10 ? '0' + R : R
        item.publishTime = N + '年' + Y + '月' + R + '日'
      })
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  async created() {
    this._loading = true;
    await this.dictionaryQuery()
    await this.buildingDynamicsDetails()
    await this.associatedBuilding()
    await this.dynamicRelatedRecommendation()
    this._loading = false;
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
}
</script>
<style lang='scss' scoped>
//@import url(); 引入公共css类
.investment-box {
  width: 1200px;
  margin: 0 auto;
  .dynamicsDetails {
    display: flex;
    justify-content: space-between;
    .contentCss {
      width: 80%;
      .contentCssName {
        font-size: 24px;
        font-weight: bold;
        color: #333333;
        font-family: Source Han Sans CN, Source Han Sans CN-Bold;
        text-align: left;
        white-space:normal;
        word-break:break-all;
      }
      .releaseTime {
        display: flex;
        justify-content: center;
        color: #999999;
        font-size: 12px;
        font-family: Source Han Sans CN, Source Han Sans CN-Regular;
        .movement {
          margin-top: 15px;
          margin-right: 20px;
        }
        .width1{
          width: 146px;
        }
        .width2{
          text-align: left;
        }
        .width3{
          min-width: 80px;
          margin-right: 0px;
          text-align: right;
        }
      }
      .introduce {
        width: 100%;
        // height: 70px;
        padding: 10px;
        background-color: #f1f2f4;
        border-radius: 3px;
        margin-top: 20px;
        .introduce_Content {
          font-size: 16px;
          color: #333333;
          font-weight: 400;
          text-align: left;
          font-family: Source Han Sans CN, Source Han Sans CN-Regular;
          white-space:normal;
          word-break:break-all;
          text-align: left;
        }
      }
      .contentInformation {
        margin: 20px 0px;
        text-indent: 50px;
        line-height: 40px;
        display: flex;
        flex-wrap: wrap;
        white-space:normal;
        word-break:break-all;
        text-align: left;
        ::v-deepp {
          width: 100%;
        }
        ::v-deep img {
          width: 100%;
        }
      }
    }
    .associatedBuildings {
      margin-left: 70px;
      width: 279px;
      .associated_Buildings {
        .associated_BuildingsName {
          display: flex;
          color: #045db9;
          font-size: 20px;
          font-weight: bold;
          font-family: Microsoft YaHei, Microsoft YaHei-Regular;
        }
        .relatedInformation {
          .careful {
            border: 1px solid #cccccc;
            margin-bottom: 20px;
            .pictureCss {
              height: 143px;
              .img {
                height: 143px;
                width: 100%;
                object-fit:cover;
              }
            }
            .building_Information {
              font-size: 10px;
              color: #999999;
              display: flex;
              padding: 10px;
              flex-direction: column;
              align-items: flex-start;
              font-family: Microsoft YaHei, Microsoft YaHei-Regular;
              font-weight: 400;

              .DaxiaName {
                margin: 10px 0px;
                color: #333333;
                font-size: 13px;
                font-weight: bold;
                font-family: Source Han Sans CN, Source Han Sans CN-Bold;
                white-space:normal;
                word-break:break-all;
                text-align: left;
              }
              .option {
                margin-bottom: 10px;
                white-space:normal;
                word-break:break-all;
                text-align: left;
              }
              .option:last-of-type {
                margin-bottom: 0px;
              }
            }
            .many {
              display: flex;
              font-size: 10px;
              font-weight: 400;
              color: #045db9;
              padding: 0px 10px 10px 10px;
              // justify-content: space-between;
              font-family: Microsoft YaHei, Microsoft YaHei-Regular;
              .multiple_Choice {
                width: 63px;
                height: 21px;
                border-radius: 3px;
                background-color: #f1f2f4;
                display: flex;
                align-items: center;
                justify-content: center;
                margin-left: 3px;
                .Choice_Name {
                  display: flex;
                  // align-items: center;
                  justify-content: center;
                  line-height: 21px;
                  height: 21px;
                  overflow: hidden;
                }
              }
            }
          }
        }
      }
      .view_More {
        line-height: 80px;
        text-decoration: underline;
        font-size: 14px;
        font-family: SimSun, SimSun-Regular;
        font-weight: 400;
        color: #333333;
        cursor: pointer;
      }
    }
  }
  .moreDynamic {
    .head {
      .MoreDynamic {
        display: flex;
        justify-content: space-between;
        .dynamicName {
          font-size: 20px;
          font-weight: bold;
          color: #045db9;
          font-family: Microsoft YaHei, Microsoft YaHei-Regular;
        }
        .moreName {
          font-size: 14px;
          color: #333333;
          font-family: Adobe Heiti Std, Adobe Heiti Std-R;
          cursor: pointer;
        }
      }
      .More_Dynamic {
        .whole {
          display: flex;
          flex-wrap: wrap;
          justify-content: space-between;
          .allCarefully {
            border: 1px solid #eeeeee;
            display: flex;
            padding: 15px;
            width: 48%;
            margin-bottom: 20px;
            .picturewhole {
              width: 140px;
              height: 139px;
              // border: 1px solid red;
              .img {
                width: 140px;
                height: 139px;
                object-fit:cover;
              }
            }
            .letter {
              width: 398px;
              display: flex;
              flex-direction: column;
              justify-content: space-between;
              margin-left: 25px;
              .writtenWords {
                display: flex;
                flex-direction: column;
                align-items: flex-start;
                .head_Name {
                  font-size: 18px;
                  font-weight: bold;
                  color: #333333;
                  margin-bottom: 20px;
                  font-family: Source Han Sans CN, Source Han Sans CN-Bold;
                  text-align: left;
                  white-space:normal;
                  word-break:break-all;
                }
                .content_Name {
                  color: #999999;
                  font-size: 14px;
                  text-align: left;
                  font-family: Source Han Sans CN, Source Han Sans CN-Regular;
                  text-align: left;
                  white-space:normal;
                  word-break:break-all;
                }
              }
              .SourceLetter {
                display: flex;
                justify-content: space-between;
                font-size: 12px;
                font-weight: 400;
                font-family: Source Han Sans CN, Source Han Sans CN-Regular;
                color: #999999;
                .sourceCss {
                  text-align: left;
                  white-space:normal;
                  word-break:break-all;
                }
                .dateCss {
                  min-width: 100px;
                  display: flex;
                  justify-content: center;
                  align-items: center;
                }
              }
            }
          }
        }
      }
    }
  }
  .ViewDetails {
    height: 160px;
    .contactBuilding {
      width: 120px;
      height: 40px;
      background: #f1f2f4;
      color: #045db9;
      border-radius: 3px;
    }
  }
  ::v-deep .el-divider--horizontal {
    margin: 15px 0;
    height: 2px;
    background-color: #045db9;
  }
}
</style>